import {findpersion,updatedata} from '../../../server/api'
import {removeImageTags} from '../../../server/shake'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    columns: [],
    show:false,
    hoursval:'1',
    phone:'',
    obj:{},
    pageNo:1,
    pageSize:10,
    records:[],
    index:'',
    id:'',
    userId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(JSON.parse(decodeURIComponent(options.obj)),'ooo');
      this.setData({obj:JSON.parse(decodeURIComponent(options.obj))})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const arr = []
    arr.push(this.data.obj)
    const numbers = [];
    for (let i = 1; i <= 1000; i++) {
      numbers.push(i);
    }
    this.setData({columns:numbers,list:arr,records:[],pageNo:1})
    this.getdata()
  },
  //获取数据
  async getdata(val){
     this.setData({records:[]})
       const params = {
        pageNo:val == undefined ? this.data.pageNo : val.pageNo,
        pageSize:val == undefined ? this.data.pageSize : val.pageSize,
         phone:this.data.phone,
         activityid:this.data.obj.id
       }
      const res = await findpersion(params)
      if(res.code == 200)
      {
        const source = res.result.records
        this.setData({records:[...this.data.records,...source]})
      }
  },
  //手机号搜索
  searchphone(){
    this.setData({records:[],pageNo:1,pageSize:10})
      this.getdata()
  },
  //选择时间确认
 async onConfirm(e){
   const val = e.detail.value
   const params = {
    activityid:this.data.obj.id,
    effectivehour:val,
    id:this.data.id,
    userid:this.data.userId
   }
   console.log(params,'params');
   const res = await updatedata(params)
   if(res.code == 200)
   {
    const index = this.data.index
    this.data.records[index].effectiveDuration = val
     this.setData({records:this.data.records,show:false})
     this.getdata()
   }
 
  },
  //取消
  onCancel(){
    this.setData({show:false})
  },
  hourchage(e)
  {
    const val =  e.currentTarget.dataset.index
    const id =  e.currentTarget.dataset.id
    const data =    this.data.records.filter((item)=> item.id == id)
    if(data[0].finishes != 1)
    {
      const userId =  e.currentTarget.dataset.userid
      this.setData({show:true,index:val,id:id,userId:userId})
    }
  },
  //分页
  getMore(){
    this.data.pageNo++
    const params = {
      pageNo:this.data.pageNo,
      pageSize:this.data.pageSize
    }
    this.getdata(params)
  },
  detail(e)
  {
    console.log(e.currentTarget.dataset.id,'eee');
    const id = e.currentTarget.dataset.id
    const types = 'hdgl'
      wx.navigateTo({
        url: `../../../subPackagesA/pages/werlfardetail/werlfardetail?id=${id}&types=${types}`,
      })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})